package Test;

import java.util.Arrays;
import java.util.Date;

import junit.framework.TestCase;

import org.junit.Test;

import data.Job;
import data.Volunteer;

/**
 * This is JUnit test for Job Test
 * 
 * @author Minh Thai, Team 5
 *
 */
public class JobTest extends TestCase {

	/**
	 * Test constructors
	 * 
	 * 1) initialize job with correct parameter
	 * 2) initialize job with null parameter
	 * 3) initialize job with invalid parameter: negative job size
	 * 4) initialize job with invalid parameter: blank inputs
	 */
	@Test
	public void testJob() {
		String description = "about";
		String name = "name";
		String location = "location";
		int grade = 4;
		int difficulty = 4;
		Date c = new Date();
		String lma = "Me";
		int jobSize = 2;
		Job j = new Job(name, "",location, grade, difficulty, 
				description, c.toString(), "", lma, 2);
		//1)
		assertTrue(j.equals(j));
		assertTrue(j.equals(new Job(name, "",location, grade, difficulty, 
				description, c.toString(), "", lma, 2)));
		assertTrue(lma.equals(j.getLMA()));
		assertTrue(jobSize == j.getJobSize());
		assertTrue(name.equals(j.getName()));
		assertTrue(location.equals(j.getLocation()));
		assertTrue(grade == j.getGrade());
		assertTrue(difficulty == j.getDifficulty());
		//2)
		Job k = new Job(null, "",null, 0, 0, 
				null, null, null, null, 5);
		assertTrue(k.getTime() == null && k.getDescription() == null &&
					k.getLMA() == null && k.getJobSize() == 1 &&
					k.getName().equals("") && k.getLocation().equals("") &&
					k.getGrade() == 0 && k.getDifficulty() == 0);
		//3)
		Job l = new Job(null, "",null, 0, 0, 
				null, null, null, null, -1);
		assertTrue(l.getJobSize() == 1);
		//4)
		Job m = new Job("", "","", 0, 0, 
				"", c.toString(), "", "", 5);
		assertTrue(m.getDescription()== null && m.getLMA() == null);
	}

	/**
	 * Test equals method
	 */
	@Test
	public void testEquals() {
		String description = "about";
		String name = "name";
		String location = "location";
		int grade = 4;
		int difficulty = 4;
		Date c = new Date();
		String lma = "Me";
		int jobSize = 2;
		Job j = new Job(name, "",location, grade, difficulty, 
				description, c.toString(), "", lma, jobSize);
		assertTrue(j.equals(j));
	}
	
	/**
	 * Test addVolunteer() method
	 * 
	 * 1) add null 
	 * 2) add duplicate volunteer
	 * 3) add when full
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testAddVolunteer() {
		//1)
		String description = "about";
		String name = "name";
		String location = "location";
		int grade = 4;
		int difficulty = 4;
		Date c = new Date();
		String lma = "Me";
		int jobSize = 2;
		Job j = new Job(name,"", location, grade, difficulty, 
				description, c.toString(), "", lma, jobSize);
		int count = j.getCurrentVolunteerSize();
		j.addVolunteer(null);
		assertTrue(j.getVolunteerList() != null && count == 0);
		//2)
		Job k = new Job(name,"", location, grade, difficulty, 
				description, c.toString(), " ", lma, jobSize);
		Volunteer v = new Volunteer("", "", "a", "", "", "",
				(new Date(10,10,10)).toString(), false);
		k.addVolunteer(v);
		assertTrue(k.getCurrentVolunteerSize() == 1);
		assertTrue(k.getVolunteerList()[1].equals(v));
		Volunteer l = new Volunteer("", "", "a", "", "", "",
				(new Date(10,10,10)).toString(), false);
		assertFalse(k.addVolunteer(l));
		//3)
		//one slot in job is reserve for leader, so we can expect full
		Volunteer n = new Volunteer("", "", "c", "", "", "",
				(new Date(10,10,10)).toString(), false);
		assertFalse(k.addVolunteer(n));
		Volunteer m = new Volunteer("", "", "c", "", "", "",
				(new Date(10,10,10)).toString(), false);
		assertFalse(k.addVolunteer(m));
	}

	/**
	 * Test removeVolunteer() method
	 * 
	 * 1) remove null 
	 * 2) remove non-exist volunteer
	 * 3) remove volunteer that exist within system
	 */
	@SuppressWarnings("deprecation")
	@Test
	public void testRemoveVolunteer() {
		//1)
		String description = "about";
		String name = "name";
		String location = "location";
		int grade = 4;
		int difficulty = 4;
		Date c = new Date();
		String lma = "Me";
		int jobSize = 2;
		Job j = new Job(name,"", location, grade, difficulty, 
				description, c.toString(), "", lma, jobSize);
		j.removeVolunteer(null);
		assertTrue(j.getVolunteerList() != null);
		//2)
		Volunteer v = new Volunteer("", "", "a", "", "", "",
				(new Date(10,10,10)).toString(), false);
		j.addVolunteer(v);
		Volunteer[] list = j.getVolunteerList();
		int volCount = j.getCurrentVolunteerSize();
		Volunteer w = new Volunteer("a", "b", "c", "", "", "",
				(new Date(10,10,10)).toString(), false);
		j.removeVolunteer(w);
		assertTrue(Arrays.equals(list, j.getVolunteerList()));
		assertTrue(j.getCurrentVolunteerSize() == volCount);	
		//3)
		j.removeVolunteer(v);
		assertTrue(j.getCurrentVolunteerSize() == 0 &&
					j.getVolunteerList()[1] == null);
	}
}
